#pragma once

#include "resource.h"
/*
    目前代码包涵里基础物体类，和继承了物体类的障碍物类，子弹类，坦克类
	其中坦克类的成员之一是子弹类
*/
typedef struct position
{
	int x, y;
}Position;

typedef struct obSize 
{
	int high, width;
} ObSize;

class BaseObject //物体类为抽象基类
{
protected:
	enum { EMPTY, TANK, BARRIER, BULLET}; // 物体的类型
	int mType;
public:
	enum { UP, RIGHT, DOWN, LEFT };
	BaseObject(int hp = 0, int x = 0, int y = 0, int high = 0, int width = 0)
	{
		mHp			 = hp;
		mPosition.x  = x; 
		mPosition.x  = y;
		mObSize.high = high;
		mObSize.high = width;
		mType		 = EMPTY; // 设置物体类型为空    
	}
	virtual ~BaseObject()			 { };
	void	 setHp(int hp)           { mHp = hp; }
	void	 setPosition(Position pt){ mPosition = pt; }
	void	 setSize(ObSize size)    { mObSize = size; }
	Position getPosition() const     { return mPosition; }
	ObSize	 getSize()     const	 { return mObSize; }
	int		 getHp()       const	 { return mHp; }
	int		 getType()	   const	 { return mType; }

	virtual bool move(Position pt);

private:
	int mHp;
	Position mPosition;
	ObSize mObSize;
};
class BarrierObject : public BaseObject
{

public:
	enum { bNULL, bBULLET, bTANK, bALL };// 全部不能穿透， 子弹可以穿透，坦克可以穿透， 全部可以穿透
	BarrierObject(int per = bNULL, int hp = 0, int x = 0, int y = 0, int high = 0, int width = 0)
		: BaseObject(hp, x, y, high, width), mPervious(per) 
	{
		BaseObject::mType = BaseObject::BARRIER;
	}
	virtual ~BarrierObject()   { };
	void setPervious(int perv) { mPervious = perv; }
	int  getPervious()	const  { return mPervious; }
private:
	int mPervious; //障碍物的穿透性
};
class BulletObject : public BaseObject
{
public:

	typedef struct levelDiff
	{
		int speed;
		int power;
	} LevelDiff;
	BulletObject(int speed = 0, int direct = UP, int power = 1, int lv = 1, int hp = 0, int x = 0, int y = 0, int high = 0, int width = 0) 
		: BaseObject(hp, x, y, high, width), mSpeed(speed), mDirection(direct), mPower(power), mLevel(lv)
	{
		BaseObject::mType = BULLET;
		mLevelDiff        = { 0 };
	}
	virtual ~BulletObject() { }

	void setSpeed(int sp)	  { mSpeed = sp;}
	void setDirection(int dt) { mDirection = dt; }
	void setPower(int pr)     { mPower = pr; }
	void setLevel(int le)	  { mLevel = le; }
	void setLevelDiff(int sp, int pr) // 设置子弹每个等级直接的数据差
	{
		
		mLevelDiff.speed = sp;
		mLevelDiff.power = pr;
	}
	void upLevel()					//子弹升级
	{
		mSpeed += mLevelDiff.speed;
		mPower += mLevelDiff.power;
		mLevel++;
	}
	virtual Position move()					//子弹移动
	{
		Position po = BaseObject::getPosition();
		switch (mDirection)
		{
		case	UP: po.y += mSpeed;
					break;
		case RIGHT: po.x += mSpeed;
					break;
		case  DOWN: po.y -= mSpeed;
					break;
		case  LEFT: po.x -= mSpeed;
		}
		BaseObject::setPosition(po);
		return po;
	}
	int  getSpeed()     const { return mSpeed; }
	int  getDirection() const { return mDirection; }
	int  getPower()	   const  { return mPower; }

private:
	LevelDiff mLevelDiff;
	int mSpeed;     //子弹速度(每次刷侦移动的距离)
	int mDirection; //子弹方向
	int mPower;     // 子弹威力， 一点威力造成一点血量的伤害
	int mLevel;     // 子弹等级
	
};


class TankObject : public BaseObject
{
public:
	enum {NORMAL, SUPER};
	TankObject(BulletObject bullet, int speed = 0, int direct = UP, int level = 1, int hp = 0, int x = 0, int y = 0, int high = 0, int width = 0)
		: BaseObject(hp, x, y, high, width), mSpeed(speed), mDirection(direct), mLevel(level), mModel(NORMAL)
	{
		BaseObject::mType = TANK;
	}
	virtual ~TankObject() {}
	void setSpeed(int sp)	  { mSpeed = sp; }
	void setDirection(int dt) { mDirection = dt; }
	void setModel(int md)     { mModel = md; }
	void setLevel(int le)	  { mLevel = le; }
	virtual Position move()					//子弹移动
	{
		Position po = BaseObject::getPosition();
		switch (mDirection)
		{
		case	UP: po.y += mSpeed;
			break;
		case RIGHT: po.x += mSpeed;
			break;
		case  DOWN: po.y -= mSpeed;
			break;
		case  LEFT: po.x -= mSpeed;
		}
		BaseObject::setPosition(po);
		return po;
	}
	int  getSpeed()     const { return mSpeed; }
	int  getDirection() const { return mDirection; }
	int  getModel()	    const { return mModel; }
private:
	BulletObject mBullet; //子弹对象
	int mSpeed;			  //坦克速度(每次刷侦移动的距离)
	int mDirection;		  //坦克方向
	int mLevel;           //坦克等级
	int mModel;			  //坦克状态
};